package com.hangzhou.xyj.ui.fragment;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.model.BannerModel;
import com.hangzhou.xyj.model.SingModel;
import com.hangzhou.xyj.model.type.EBannerType;
import com.hangzhou.xyj.net.handler.GetBannerHandler;
import com.hangzhou.xyj.net.handler.SingRecommedHandler;
import com.hangzhou.xyj.net.http.HttpLoader;
import com.hangzhou.xyj.net.request.GetBannerReq;
import com.hangzhou.xyj.net.request.SingRecommendReq;
import com.hangzhou.xyj.ui.adapter.DianDramaStageAdapter;
import com.hangzhou.xyj.ui.fragment.base.BaseFragment;

import java.util.List;

/**
 * 首页唱戏：点戏台
 *
 * @author neo.duan
 */
public class DianDramaStageFragment extends BaseFragment implements OnClickListener {

    private RecyclerView mRecyclerView;
    private LinearLayoutManager mLayoutManager;
    private DianDramaStageAdapter mAdapter;

    @Override
    public void initTop() {
        enableTop(false);
    }

    @Override
    public void initLayouts() {
        setContentView(R.layout.fragment_dian_drama_stage);
    }

    @Override
    public void initViews() {
        mRecyclerView = findView(R.id.rv_dian_drama);
        // 设置item动画
        mLayoutManager = new LinearLayoutManager(mContext);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public void initDatas() {
        mAdapter = new DianDramaStageAdapter(mContext);
        mRecyclerView.setAdapter(mAdapter);
        //向服务器请求 推荐曲目
        SingRecommendReq singRecommendReq = new SingRecommendReq();
        HttpLoader.getInstance().sendRequest(new SingRecommedHandler(singRecommendReq, new MyHttpResponseListener() {
            @Override
            public void onSuccess(Object model) {
                super.onSuccess(model);
                mAdapter.updateRecommendDramaData((List<SingModel>) model);
            }
        }, 0));
        //向服务器请求 Banner
        GetBannerReq req = new GetBannerReq(EBannerType.DIAN_STAGE);
        HttpLoader.getInstance().sendRequest(new GetBannerHandler(req, new MyHttpResponseListener() {
            @Override
            public void onSuccess(Object model) {
                //super.onSuccess(model); 不需要关闭Loading对话框，所以注释掉
                //更新banner数据
                List<BannerModel> bannerList = (List<BannerModel>) model;
                mAdapter.updateBannerData(bannerList);
            }
        }, 0));
    }

    @Override
    public void initListeners() {

    }

    @Override
    public void onClick(View v) {

    }
}
